Skip to content

ZSTD support - #34

Open
jschueller wants to merge 13 commits into
nsis-dev:masterfrom
jschueller:zstd
Open

ZSTD support#34
jschueller wants to merge 13 commits into
nsis-dev:masterfrom
jschueller:zstd

Conversation

@jschueller

@jschueller jschueller commented Aug 15, 2026

Copy link
Copy Markdown

refreshed #28 without the math changes, and no asm, as requested
also forwarded the new data size argument to zstd

/cc @dbeinder @sredna

@jschueller
jschueller force-pushed the zstd branch 2 times, most recently from f071d68 to 56e62fb Compare August 15, 2026 19:27
Comment thread Contrib/zip2exe/Base.nsh Outdated
@jschueller
jschueller force-pushed the zstd branch 3 times, most recently from 6d44cca to 2dbdabc Compare August 15, 2026 21:07
@jschueller
jschueller marked this pull request as ready for review August 15, 2026 21:08
@jschueller

Copy link
Copy Markdown
Author

hello @sredna, would it be possible to approve the workflow to at least run the CI ?
ping @dbeinder

@dbeinder

dbeinder commented Aug 29, 2026

Copy link
Copy Markdown

Thank you for updating my PR! I'm not part of the NSIS team though, so I can't really help you get this merged.

I see you've updated zstd - I had made a few patches to reduce the size of exehead: https://github.com/dbeinder/nsis/blob/d353438eff9244cc2416e1b7bb0b17551a25941d/Source/zstd/zstd-v1.5.6.diff
It basically strips out unused code for unpacking with the help of a separate dictionary file and the built-in XXH64 checksum which should be redundant.

Not sure if this is still worth doing, or if the NSIS team considers minimal exehead size a priority.

@jschueller

Copy link
Copy Markdown
Author

I think its best not to alter the zstd sources for easier maintenance, or changes must be upstreamed first

@dbeinder

dbeinder commented Aug 29, 2026

Copy link
Copy Markdown

Well it's a matter of priorities - I think it's safe to say NSIS isn't on the "update dependencies and push a release every week" side of the spectrum ;)
https://github.com/nsis-dev/nsis/blob/master/Source/7zip/sdk.diff
image
But tbh, I don't even remember how much difference the #ifdefs it made, and I don't have a VC6 toolchain set up to re-test. Where do you land with the zstd stubs? In my old PR I got to ~90kiB.

@jschueller

Copy link
Copy Markdown
Author

I did not check the minimal size : my use-case is for a large archive that takes forever to compress.

realloc copied the new size instead of min(old,new); memmove used unsigned int instead of size_t; memset was missing for MSVC /nodefaultlib builds; calloc lacked overflow and NULL checks; memcpy is now word-at-a-time. Also fix nsis_rotl (shift 0 UB), nsis_rotl64 (>=32 rotate), nsis_byteswap_uint64 (halves swapped), nsis_allmul (missing carry and cross terms) and nsis_allshl (rotated low half).
The NSIS_* wrappers were dead code: bundled threading.h called Vista+ imports directly, breaking the XP-compat design. Route the pthread condvar macros through DynamicCondVars and fix its header linkage (proper extern "C" block) and GetProcAddress casts.
AddZstd never ran the configure check on win32 so LIBS was never set; unify both platforms through CheckLibWithHeader, require >= 1.4.0, and define USE_SYSTEM_ZSTD so sources include <zstd.h> instead of mixing bundled headers with a system library. Also detect zstd.dll besides libzstd.dll.
Both branches appended ZSTD_MULTITHREAD; always define it (DynamicCondVars is always compiled) and only add bundled sources when no system zstd is used.
Use cores-1 workers, skip multithreading for single-core machines and inputs under 256KB, and fall back to single-threaded if the library rejects nbWorkers. Clamp levels defensively, support <zstd.h> for system builds, use a thread-local error buffer, and include <unistd.h> directly instead of relying on transitive includes.
Accept 0-19 regardless of the currently selected compressor (restores level 0 and allows SetCompressionLevel before SetCompressor); each compressor clamps to its own range in Init instead of failing the build.
Define ZSTD_MULTITHREAD like makensis, support system zstd via USE_SYSTEM_ZSTD, always compile DynamicCondVars.c (CZstd needs ConditionVarsSupported in both modes), and add an include guard to decompress.h.
The BMI2 asm loop object is not part of the stub build, so gcc/mingw links failed; disable runtime BMI2 dispatch as the unit tests already do. Also document that the session-only reset preserves the magicless format.
Move the zip2exe Solid checkbox so it no longer overlaps the ZLib radio button, and extend all toolbar strips to 15 frames (duplicating the BZIP2 icon as a placeholder until dedicated ZSTD art exists).
@jschueller

Copy link
Copy Markdown
Author

@sredna I pushed a batch of fixes, would it be possible for you to trigger the CI run ?

Document zlib 0-9 range with clamping when levels are set before SetCompressor,
and drop the stale 34KB stub overhead claim which no longer holds for zstd stubs.
MSVC stub builds compile SCons/Config/memset.c, which clashed with the unconditional memset in crt_replacements.c (LNK2005). Guard both definitions with _NSIS_NODEFLIB_CRTMEMSET/_NSIS_NODEFLIB_CRTMEMCPY, defining the former in SCons/Config/ms and both in SCons/Config/gnu, mirroring the existing mini_memcpy precedent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants